import Vue from 'vue'
import Router from 'vue-router'
import { getNavigationList } from "@/api/blog/blogNavigation";
import {ref} from 'vue'

Vue.use(Router)

export async function fetchRoutes(){
    try{
 // 调用你的后端API
    const routesData = ref([]);
    getNavigationList({navigationType: 1}).then(response => {
        routesData.value = response.data
    // 根据后端返回的数据动态添加路由
    routesData.value.forEach(route => {
        const routeComponent = () => import(`../views/${route.navigationComponentName}`) // 动态导入组件
        router.addRoute({ path: route.navigationRouter, component: routeComponent });
      });
      })
    }catch(error){
        console.error('加载路由失败了:', error);
    }
}

const router =new Router({
  mode: 'history',
  base: process.env.BASE_URL
})

export default router